package com.wh.wisdomsite.xbox.ba.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.wh.wisdomsite.xbox.ba.dao.CommonFileMapper;
import com.wh.wisdomsite.xbox.ba.entity.CommonFile;
import com.wh.wisdomsite.xbox.ba.service.ICommonFileService;
import com.wh.wisdomsite.xbox.utils.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 公共附件serviceImpl
 * @author 刘旭
 * @version V1.0
 * @Package com.wh.wisdomsite.xbox.ba.service.impl
 * @date 2018年08月03日 15:52
 * @Copyright 企业版权所有
 * @Company 贵州万华科技有限公司CopyRight (c) 2018
 */
@Service("baCommonFile")
@Transactional(rollbackFor = {Exception.class,RuntimeException.class})
public class CommonFileServiceImpl extends ServiceImpl<CommonFileMapper, CommonFile> implements ICommonFileService {
    private static final Log logger = LogFactory.getLog(CommonFileServiceImpl.class);

    @Autowired
    private CommonFileMapper commonFileMapper;

    @Override
    public CommonFile getById(String id) {
        return commonFileMapper.selectById(id);
    }

    @Override
    public void save(CommonFile commonFile) {
        try{
            if(StringUtils.isNotEmpty(commonFile.getFileId())){
                commonFileMapper.updateById(commonFile);
            }else{
                commonFileMapper.insert(commonFile);
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.error("添加公共附件Exception: " + e.getMessage());
            throw new RuntimeException("添加公共附件异常");
        }
    }

    @Override
    public void deleteById(String id) {
        try{
            commonFileMapper.deleteById(id);
        }catch (Exception e){
            e.printStackTrace();
            logger.error("删除公共附件Exception: " + e.getMessage());
            throw new RuntimeException("删除公共附件异常");
        }
    }

}
